package sv.gob.mh.dgii.model.validators;

import java.lang.reflect.Method;

import javax.validation.ConstraintValidator;
import javax.validation.ConstraintValidatorContext;
import sv.gob.mh.dgii.model.custom.constraints.ValidateIf;

public class IfValidator implements ConstraintValidator<ValidateIf, Object> {

	 	private String metodo;
	 	private String propiedad;

	    public void initialize(ValidateIf constraintAnnotation) {
	    	this.propiedad = constraintAnnotation.propiedad();
	        this.metodo = constraintAnnotation.metodo();
	    }

	    public boolean isValid(Object value, ConstraintValidatorContext constraintContext) {	    	
	    	Method m;
			try {
				m = value.getClass().getMethod(metodo, null);
				Object res = m.invoke(value, (Object[])null);
				System.out.println(res);
			} catch (Exception e) {
				e.printStackTrace();
			}
	    	
	    	//constraintContext.disableDefaultConstraintViolation();
	    	return false;	    	
	    }

}
